package com.rm.zeyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rm.zeyou.entity.TechnicianZfbCount;
import com.rm.zeyou.mapper.TechnicianZfbCountMapper;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.TechnicianZfbCountService;
import com.rm.zeyou.util.check.CheckEmptyUtil;
import com.rm.zeyou.voice.vo.request.AddZfbCountVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 * 技师支付宝账户表 服务实现类
 * </p>
 *
 * @author YanYang
 * @since 2025-04-17 12:35:05
 */
@Service
public class TechnicianZfbCountServiceImpl extends ServiceImpl<TechnicianZfbCountMapper, TechnicianZfbCount> implements TechnicianZfbCountService {
    @Resource
    private TechnicianZfbCountMapper technicianZfbCountMapper;

    @Transactional(rollbackFor = RuntimeException.class)
    @Override
    public ApiRestResponse<Integer> addTechnicianZfbCount(Long tid, AddZfbCountVo requestVo) {
        TechnicianZfbCount userZfbCount = new TechnicianZfbCount();
        userZfbCount.setTid(tid);
        userZfbCount.setUserName(requestVo.getUserName());
        userZfbCount.setUserTel(requestVo.getUserTel());
        int insert = technicianZfbCountMapper.insert(userZfbCount);
        return ApiRestResponse.success(insert);
    }

    @Override
    public ApiRestResponse<AddZfbCountVo> selectTechnicianZfbCount(Long tid) {
        TechnicianZfbCount userZfbCount = technicianZfbCountMapper.selectOne(new LambdaQueryWrapper<TechnicianZfbCount>()
                .eq(TechnicianZfbCount::getTid, tid));
        AddZfbCountVo addZfbCountVo = new AddZfbCountVo();
        if (!CheckEmptyUtil.isEmpty(userZfbCount)) {
            addZfbCountVo.setUserName(userZfbCount.getUserName());
            addZfbCountVo.setUserTel(userZfbCount.getUserTel());
        }
        return ApiRestResponse.success(addZfbCountVo);
    }

    @Transactional(rollbackFor = RuntimeException.class)
    @Override
    public ApiRestResponse<Integer> updateTechnicianZfbCount(Long tid, AddZfbCountVo requestVo) {
        TechnicianZfbCount userZfbCount = technicianZfbCountMapper.selectOne(new LambdaQueryWrapper<TechnicianZfbCount>()
                .eq(TechnicianZfbCount::getTid, tid));
        userZfbCount.setUserName(requestVo.getUserName());
        userZfbCount.setUserTel(requestVo.getUserTel());
        int update = technicianZfbCountMapper.updateById(userZfbCount);
        return ApiRestResponse.success(update);
    }

}
